import {useCrumbs} from "../store/crumbs";
import {ref} from "vue";
// 封装面包屑
interface Cru {
    head?: string;
    footer?: string
}
export let crumbsObj: Cru = {}
const crumbStore = useCrumbs()
export const crus = (path: string) => {
    let pathStr = path.split('/')
    let pathArr = []
    // 头
    let header = ''
    for (const pathKey in crumbStore.crumbObj) {
        pathArr.push(pathKey)
    }
    let res = pathArr.filter(item => {
        if (new RegExp(pathStr[1]).test(item)) return item
    })
    // 判断头
    if (res.length > 1) {
        header = res[res.length - 1]
    } else header = res[0]
    interface PathObj {
        head: string;
        footer?: string
    }
    let pathObj: PathObj = {
        head: header,
        footer: path
    }
    crumbsObj = pathObj
    if (res.length === 1) delete pathObj.footer
    if (crumbStore.pathArrs) crumbStore.pathArrs = []
    crumbStore.pathArrs.push(crumbStore.crumbObj[crumbsObj.head as keyof typeof crumbStore.crumbObj],
        crumbStore.crumbObj[crumbsObj.footer as keyof typeof crumbStore.crumbObj])
}
